package main

import (
	"fmt"
	"gitee.com/xiakai001/goutl/cmdutl"
	"gitee.com/xiakai001/goutl/errutl"
	"os"
	"path/filepath"
	"strings"
)

func main() {

	defer func() {
		for {
			_, _ = fmt.Scanln()
		}
	}()

	err := handle()
	if err != nil {
		println(err.Error())
	}

}

func handle() error {
	if len(os.Args) == 1 {
		println("无文件路径")
		return nil
	}

	filePath := os.Args[1]
	dirPath := strings.TrimSuffix(filePath, filepath.Ext(filePath))

	err := os.Mkdir(dirPath, os.ModeDir)
	if err != nil {
		return errutl.Wrap(err)
	}

	args := []string{"-hwaccel", "auto", "-y", "-i", filePath, "-pix_fmt", "rgb24", fmt.Sprintf("%s\\extracted_%%0d.png", dirPath)}
	println("ffmpeg", strings.Join(args, " "))

	err = cmdutl.ExecWithArgs("ffmpeg", args)
	if err != nil {
		return errutl.Wrap(err)
	}

	println()
	println()
	println("success!!")
	println()
	println()

	return nil
}
